var vm = new Vue({
    el: '#contentContainer',
    data: {
        form: {
            datasetName: '',
            sqlString: '',
            remark: '',
        },
        rules: {
            datasetName: [
                {required: true, message: '请输入数据集名称', trigger: 'blur'},
                {min: 0, max: 150, message: '长度不能超过150个字符', trigger: 'blur'}
            ],
            sqlString: [
                {required: true, message: '请输入数据集SQL', trigger: 'blur'},
                {min: 0, max: 1024, message: '长度不能超过1024个字符', trigger: 'blur'}
            ]
        }
    },
    methods: {
        submitForm: function (formName) {
            var $this = this;

            $this.$refs[formName].validate(function (valid) {
                if (!valid)
                    return false;

                Common.postJson('/sys/dataset/add', $this.form,
                    function (response) {
                        if (!response)
                            return;

                        //保存成功
                        if (response.status == 200 && response.result.success)
                            window.location.href = '/sys/dataset/list';
                        else {
                            var errMsg = response.status == 200 ? response.result.errMsg : response.msg;

                            $this.$notify.error({
                                title: '错误',
                                message: errMsg,
                                offset: $("#main", window.parent.document).height() - 120,
                                duration: 0
                            });
                        }
                    });
            });
        },
        resetForm: function (formName) {
            this.$refs[formName].resetFields();
        }
    }
});